package cn.kkcxy.blog.system.factory.wechat.impl;

import cn.kkcxy.blog.core.enums.WeChatMessageTypeEnum;
import cn.kkcxy.blog.system.factory.wechat.WechatMessageHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;

/**
 * @Author: CK
 * @Date: 2024/06/18/17:39
 * @Description:
 */
@Slf4j
@Component
public class SubscribeMessageHandler implements WechatMessageHandler {

    @Override
    public WeChatMessageTypeEnum getMessageType() {
        return WeChatMessageTypeEnum.SUBSCRIBE;
    }

    @Override
    public String dealMsg(Map<String, String> msgMap) {
        log.info("接收到用户关注公众号消息");
        String toUserName = msgMap.get("ToUserName");
        String fromUserName = msgMap.get("FromUserName");

        String subscribeContent = "欢迎关注! 博客登录在消息栏发送[验证码]即可获取登录验证码！";
        String msg = "<xml><ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>\n" +
                "<FromUserName><![CDATA[" + toUserName + "]]></FromUserName>\n" +
                "<CreateTime>" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss")) + "</CreateTime>\n" +
                "<MsgType><![CDATA[text]]></MsgType>\n" +
                "<Content><![CDATA[" + subscribeContent + "]]></Content>\n" +
                "</xml>";
        return msg;
    }
}
